/**
 * Implementation of a singleton logger class
 */
#include <string>
#include "Logger.h"
using namespace std;

const string Logger::kLogLevelDebug = "DEBUG";
const string Logger::kLogLevelInfo = "INFO";
const string Logger::kLogLevelError = "ERROR";

const char* const Logger::kLogFileName = "log.out";

bool Logger::sInitialized = false;
ofstream Logger::sOutputStream;

void Logger::init()
{
	if(!sInitialized) {
		sOutputStream.open(kLogFileName, ios_base::app);
		if(!sOutputStream.good() ) {
			cerr << "Unable to initialize the Logger!" << endl;
			return;
		}
		sInitialized = true;
	}
}

void Logger::teardown()
{
	if(sInitialized) {
		sOutputStream.close();
		sInitialized = false;
	}
}

void Logger::log(const string& inMessage, const string& inLogLevel)
{
	if(!sInitialized)
		init();
	sOutputStream << "[" << inLogLevel << "]" << inMessage << endl;
}

void Logger::log(const vector<string>& inMessages, const string& inLoglevel)
{
	for (size_t i=0; i<inMessages.size(); i++) {
		log(inMessages[i], inLoglevel);
	}
}

